# -*- coding: utf-8 -*-
# @Time    : 2025/1/8 16:48
# @Author  : Z.J. Zhang
# @Email   : zijingzhang@mail.ustc.edu.cn
# @File    : aaa.py
# @Software: PyCharm
import matplotlib.pyplot as plt
import numpy
import matplotlib

matplotlib.use('tkagg')
plt.ion()
f_0 = 300

t = numpy.arange(0, 1/f_0 * 2,1/f_0 /200, )
dt = t[1]-t[0]
signal = 25  * numpy.cos(2 *numpy.pi*f_0 * t + 0.1)
plt.figure()
plt.plot(t, signal)


from scipy.interpolate import  interp1d
signal_f = interp1d(t, signal)
# t_1period = numpy.arange(0, 1/f_0, 1/f_0 / 200)
a_1 = (signal_f(t)  * numpy.cos(2*numpy.pi * f_0 * t)  * dt ).sum() * 2 /(t[-1]-t[0])
b_1 = (signal_f(t)  * numpy.sin(2*numpy.pi * f_0 * t)  * dt ).sum() * 2 /(t[-1]-t[0])
print(a_1)
print(b_1)
print((a_1**2 + b_1 **2 )**0.5)